package com.springboot.personblogsystem.controller;

import com.springboot.personblogsystem.common.Result;
import com.springboot.personblogsystem.common.req.AddBlogParam;
import com.springboot.personblogsystem.common.req.UpdateBlogParam;
import com.springboot.personblogsystem.common.resp.ArticleResponse;
import com.springboot.personblogsystem.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description :
 * User: jiume
 * Date: 2025-05-14
 * Time: 17:15
 */
@RequestMapping("/blog")
@RestController
public class BlogController {

    @Resource
    private BlogService blogService;

    // 获取文章总数接口
    @GetMapping("/getBlogCount")
    public Result<Long> getBlogCount(HttpServletRequest request) {
        return blogService.getBlogCount(request);
    }

    // 获取文章分类接口
    @GetMapping("/getBlogSort")
    public Result<Long> getBlogSort(HttpServletRequest request) {
        return blogService.getBlogSort(request);
    }

    // 获取博客文章接口
    @GetMapping("/getBlog")
    public Result<List<ArticleResponse>> getBlog(HttpServletRequest request) {
        return blogService.getBlog(request);
    }

    // 获取完整博客信息接口
    @GetMapping("/getBlogDetail")
    public Result<ArticleResponse> getBlogDetail(Long articleId) {
        return blogService.getBlogDetail(articleId);
    }

    // 新增博客接口
    @PostMapping("/addBlog")
    public Result<Boolean> addBlog(@RequestBody AddBlogParam addBlogParam,
                                   HttpServletRequest request) {
        return blogService.addBlog(addBlogParam, request);
    }

    // 更新博客接口
    @PutMapping("/updateBlog")
    public Result<Boolean> updateBlog(@RequestBody UpdateBlogParam updateBlogParam) {
        return blogService.updateBlog(updateBlogParam);
    }

    // 删除博客接口
    @DeleteMapping("/deleteBlog")
    public Result<Boolean> deleteBlog(Long articleId) {
        return blogService.deleteBlog(articleId);
    }
}
